//
//  AppDelegate.m
//  QuickDoctor
//
//  Created by Eric on 2016-12-20.
//  Copyright © 2016 Eric. All rights reserved.
//

#import "AppDelegate.h"
#import "QDMainViewController.h"
#import "QDSideslippingViewController.h"
#import "DWLaunchScreen.h"

#import "UMSocial.h"
#import "UMSocialWechatHandler.h"
#import "UMSocialQQHandler.h"
#import "UMSocialSinaSSOHandler.h"
#define AppKey @"5744171667e58e89d80015ae"


@interface AppDelegate ()<DWLaunchScreenDelegate>

//侧滑控制器
@property (nonatomic, strong) JASidePanelController *panelController;

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    //创建window
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    
    self.panelController = [[JASidePanelController alloc] init];
    
    self.panelController.leftPanel = [[QDSideslippingViewController alloc] init];
    self.panelController.leftPanel.view.backgroundColor = [UIColor whiteColor];
    
    QDMainViewController *viewC = [QDMainViewController new];
    self.panelController.centerPanel = [[UINavigationController alloc] initWithRootViewController:viewC];

    self.window.backgroundColor = [UIColor whiteColor];
    
    self.window.rootViewController = self.panelController;
    
    [self.window makeKeyAndVisible];
    
    [self setNaviBack];
    
    DWLaunchScreen *launchScreen = [[DWLaunchScreen alloc] init];
    launchScreen.delegate = self;
    launchScreen.deleteLength = 1.0f;
    launchScreen.skipTimerHide = NO;
    
    launchScreen.disappearType = DWCrosscutting;
    //字体颜色
    launchScreen.skipTitleColor = [UIColor blackColor];
    
    //字体大小
    launchScreen.skipFont = 18;
    
    //按钮背景颜色
    launchScreen.skipBgColor = [UIColor clearColor];
    
    //按钮显示位置
    launchScreen.skipLocation = RightTop;
    
    //按钮文字
    launchScreen.skipString = @"跳过";
    
    //网络时的渲染图，建议与启动图相同
    launchScreen.logoImage = [UIImage imageNamed:@"Default"];
    
    [launchScreen dw_LaunchScreenContent:[UIImage imageNamed:@"Default"] window:self.window withError:nil];
    
    
    [UMSocialData setAppKey:AppKey];
    //设置微信AppId、appSecret，分享url
    [UMSocialWechatHandler setWXAppId:@"wxd930ea5d5a258f4f" appSecret:AppKey url:@"http://www.umeng.com/social"];
    //设置手机QQ 的AppId，Appkey，和分享URL，需要#import "UMSocialQQHandler.h"
    [UMSocialQQHandler setQQWithAppId:@"100424468" appKey:AppKey url:@"http://www.umeng.com/social"];
    //打开新浪微博的SSO开关，设置新浪微博回调地址，这里必须要和你在新浪微博后台设置的回调地址一致。需要 #import "UMSocialSinaSSOHandler.h"
    [UMSocialSinaSSOHandler openNewSinaSSOWithAppKey:@"819272468" secret:@"da00667b7bad3ffd8038a93078eef975" RedirectURL:@"http://sns.whalecloud.com/sina2/callback"];
    
    return YES;
}

#pragma mark
#pragma mark - 可回调信息
//回调信息
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    BOOL result = [UMSocialSnsService handleOpenURL:url];
    if (result == FALSE) {
        //调用其他SDK，例如支付宝SDK等
    }
    return result;
}


#pragma mark ---点击了图片，只有图片格式时才生效
- (void)dw_didSelectImageView {
    
    NSLog(@"点击了图片");
    
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"点击了图片" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
}

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    [[NSURLCache sharedURLCache] removeAllCachedResponses];
}



- (void)setNaviBack{
    
    UINavigationBar * navigationBar = [UINavigationBar appearance];
    
    //设置返回样式图片
    
    UIImage *image = [UIImage imageNamed:@"jiantou"];
    
    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    navigationBar.backIndicatorImage = image;
    
    navigationBar.backIndicatorTransitionMaskImage = image;
    
    UIBarButtonItem *buttonItem = [UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil];
    
    UIOffset offset;
    
    offset.horizontal = - 500;
    
    offset.vertical =  - 500;
    
    [buttonItem setBackButtonTitlePositionAdjustment:offset forBarMetrics:UIBarMetricsDefault];
    
}



@end
